package handler

import (
	"github.com/gin-gonic/gin"
	"yk1-assistant/models"
)

func UserRoleList2(c *gin.Context) {
	var role []models.Role
	uid := c.Query("uid")
	//SELECT *
	//	FROM roles
	//LEFT JOIN user_roles ON user_roles.rid=roles.id
	//WHERE user_roles.uid=1
	models.DB.Table("roles").
		Joins("LEFT JOIN user_roles ON user_roles.rid=roles.id").Where("user_roles.uid=?", uid).
		Find(&role)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": role,
	})
	return
}
func RoleNodeList2(c *gin.Context) {
	var node []models.Node
	rid := c.Query("rid")
	//SELECT *
	//	FROM roles
	//LEFT JOIN user_roles ON user_roles.rid=roles.id
	//WHERE user_roles.uid=1
	models.DB.Table("nodes").
		Joins("LEFT JOIN role_nodes ON role_nodes.nid=node.id").Where("role_nodes.rid=?", rid).
		Debug().Find(&node)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": node,
	})
	return
}
